package webir.newsaggregator;

import java.sql.ResultSet;
import java.sql.SQLException;
import java.text.SimpleDateFormat;

import net.viral.struts2.Connect;

import webir.newsaggregator.Feed;
import webir.newsaggregator.FeedMessage;
import webir.newsaggregator.RSSFeedParser;


public class ReadTest {

	public void iterate() throws SQLException
	{
		new SimpleDateFormat("");
		Connect c = new Connect();
		try
		{
		ResultSet rs = c.getResult("select * from linkcat");
		while (rs.next()) {
			String link=rs.getString("link");
			RSSFeedParser parser = new RSSFeedParser(link);
			Feed feed = parser.readFeed();
			System.out.println(feed);
			System.out.println("_____________________________________________________");
			for (FeedMessage message : feed.getMessages()) {
				System.out.println(message);
				System.out.println("_____________________________________________________");
			}
		}
		}catch(Exception ex){}
	}

	@SuppressWarnings("static-access")
	public void insertNewsFirstTime(String link, String category){
		RSSFeedParser parser = new RSSFeedParser(link);
		Feed feed = parser.readFeed();
		if(feed == null) return;
		System.out.println(feed);
		System.out.println("_____________________________________________________");
		for (FeedMessage message : feed.getMessages()) {
			System.out.println(message);
			System.out.println("_____________________________________________________");
		}

	}

	public static void main(String[] args) throws SQLException {
		ReadTest r=new ReadTest();
		r.iterate();
	}
}
